package net.dgg.zz.common.controller;

import com.alibaba.fastjson.JSONObject;
import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.http.HttpUtility;
import net.dgg.zz.common.entity.QdsScOrderVo;
import net.dgg.zz.common.excption.CommonExcption;
import net.dgg.zz.common.service.OrderApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 资质生产相关接口api
 *<p>@Package: net.dgg.zz.common.controller</p>
 *<p>@Title：OrderApiController</p>
 *<p>@description:</p>
 *<p>@author liulei</p>
 *<p>@date 2018年8月29日</p>
 *<p>@Company dgg</p>
 */
@Controller
@RequestMapping("zzsc/api")
public class OrderApiController extends DggBaseController {
	
	
	
	@Autowired
	private OrderApiService apiservice;
	
	
	/**
	 * iBoss下单插入订单接口 审核通过调用
	 * @return
	 */
	@ResponseBody
	@RequestMapping("inset_order")
	public DggRestResponse insertOrder(String order, String products){
		try{
			apiservice.insertOrder(order,products);
			return this.getSuccessResponse("保存成功");
		}catch (Exception e){
			e.printStackTrace();
			return this.getFailResponse(e.getMessage());
		}
	}

	/**
	* <p>@Description IBOSS第一次调用接口</p>
	* <p>@author mqy</p>
	* <p>@Time 2018/11/23 0023 11:58 创建时间</p>
	* <p>@return</p>
	*/
	@ResponseBody
	@RequestMapping("inset_order_temp")
	public DggRestResponse insetOrderTemp(String returnUrl,String notifyUrl,String order){
		try{
			//orderId	Long	订单编号	000000
			//status	String	下单状态	ORF_DDZT_ORDER_OK 表示下单成功
			JSONObject orderObj = JSONObject.parseObject(order);
			Map notiMap = new HashMap<String,Object>(){{
				put("orderId", Long.valueOf(orderObj.get("orderId").toString()));
				put("status", "ORF_DDZT_ORDER_OK");
			}};

			//{“code”:0,“msg”: “操作成功”,“data”:{“redirect”:“http://www.baidu.com”}}
			HttpUtility.postRest(notifyUrl,notiMap);//通知
			Map data = new HashMap<String,Object>(){{put("redirect",returnUrl);}};
			return this.getSuccessResponse(data);
		}catch (Exception e){
			return this.getFailResponse(e.getMessage());
		}
	}

	/**
	* <p>@Description IBOSS调用查询接口</p>
	* <p>@author mqy</p>
	* <p>@Time 2018/11/23 0023 13:40 创建时间</p>
	* <p>@return</p>
	*/
	@ResponseBody
	@RequestMapping("query_order_temp")
	public DggRestResponse queryOrderTemp() {
		//{“code”: 0,“msg”: “下单成功”, “data”:{“status”:“ORF_DDZT_ORDER_OK”}}
		Map data = new HashMap<String, Object>() {{
			put("status", "ORF_DDZT_ORDER_OK");
		}};
		return this.getSuccessResponse(data);
	}
}
